<?
	include "inc_security.php";	
	//Kiem tra quyen them sua xoa
	checkAddEdit("add");
    $listAll = array('- Danh mục -');
	if($admin_role['rol_vip'] == 1 || $admin_role['rol_vip'] == 2){
	   //Vip
       $menu 	= new menu();
	   $listAll = $menu->getAllChild("categories_multi","cat_id","cat_parent_id","0","lang_id = " . $lang_id . $sqlcategory,"cat_id,cat_name,cat_order,cat_type,cat_parent_id,cat_has_child","cat_order ASC, cat_name ASC","cat_has_child");   
	}else{
	   $db_mycat = new db_query('SELECT cat_id, cat_name 
                                 FROM categories_multi 
                                 LEFT JOIN admin_user_category ON cat_id = auc_category_id 
                                 WHERE auc_admin_id = '.$admin_id .' 
                                 ORDER BY cat_id ASC');
        while($row = mysql_fetch_assoc($db_mycat->result)){
            $listAll[$row['cat_id']] = $row['cat_name'];
        }
        unset($db_mycat);
	}
	$fs_action		=	"";
	$fs_errorMsg	=	"";
	$new_title_md5	=	md5(strtolower(getValue("new_title", "str", "POST", "", 1)));
	$new_date		=	time();
    
    /* -------------------- */
	$new_detail = removeScript(getValue('new_detail','str','POST',''));
    //add link sources
    $new_detail = str_replace('http://vcamp.vn/article/','/article/',$new_detail);
    $new_detail = str_replace('/article/','http://vcamp.vn/article/',$new_detail);
    /* -------------------- */
    //New relate list
    $new_relate_list = getValue('new_relate_list','arr','POST','');
    if(is_array($new_relate_list)){
        $new_relate_list = array_unique($new_relate_list);
        $new_relate_list = implode('|',$new_relate_list);
    }
    //New recommend list
    $new_recommend_list = getValue('new_recommend_list','arr','POST','');
    if(is_array($new_recommend_list)){
        $new_recommend_list = array_unique($new_recommend_list);
        $new_recommend_list = implode('|',$new_recommend_list);
    }
    /* -------------------- */
	$myform	=	new generate_form();
	$myform->removeHTML(0);
	$myform->add('new_cat_id', 'new_cat_id', 1, 0, '', 1, 'Bạn chưa chọn danh mục', 0, '');
    $myform->add('new_event_id', 'new_event_id', 1, 0, '', 0, '', 0, '');
    $myform->add('new_pitching_id', 'new_pitching_id', 1, 0, '', 0, '', 0, '');
    $myform->add('new_relate_list', 'new_relate_list', 0, 1, '', 0, '', 0, '');
    $myform->add('new_recommend', 'new_recommend_list', 0, 1, '', 0, '', 0, '');
	$myform->add('new_title', 'new_title', 0, 0, '', 1, 'Bạn chưa nhập tiêu đề tin', 0, "");
	$myform->add('new_teaser', 'new_teaser', 0, 0, '', 0, "", 0 , "");
	$myform->add('new_detail', 'new_detail', 0, 1, '', 0, "", 0, "");
    $myform->add('new_admin_id','admin_id',1,1,0,1,'User không tồn tại');
    $myform->add("new_sou_id", "new_sou_id", 1, 0, 0, 0,"",0,"");
	$myform->add('new_tags', 'new_tags', 0, 0, '', 0, '', 0, '');
    $myform->add('new_tags_to_base', 'new_tags_to_base', 0, 0, '', 0, '', 0, '');
	$myform->add('new_author', 'new_author', 1, 0, '', 0, '', 0, '');
	$myform->add("new_date", "new_date", 1, 1, 0, 0, "", 0, "");
    $myform->add("new_top", "new_top", 1, 0, 0, 0,"",0,"");
    $myform->add("new_top_index", "new_top_index", 1, 0, 0, 0,"",0,"");
    $myform->add("new_hot", "new_hot", 1, 0, 0, 0,"",0,"");
    $myform->add("new_coin","new_coin",1, 0, 0, 0,"",0,"");
    if($admin_role['rol_edit'] || $admin_role['rol_vip']){
        //Thêm nút tiêu điểm
        $myform->add('new_focus','new_focus',1,0,0);
    }
	$myform->addTable($fs_table);
	
	$action			= getValue("action","str","POST","");
	if($action 		== 'execute'){
        //Relate categories
        $relate_cat = getValue('relate_cat','arr','POST','');
        if($relate_cat){
            $relate_cat = implode('|',$relate_cat);
            $myform->add('new_relate','relate_cat',0,1,'');
        }
		//Check form data
		$fs_errorMsg .= $myform->checkdata();
		if($fs_errorMsg == ""){
            //Up ảnh đại diện
			$upload		= new upload($fs_fieldupload, $fs_filepath, $fs_extension, $fs_filesize);
			$filename	= $upload->file_name;
			if($filename != ""){
				$myform->add("new_picture", "filename", 0, 1, "", 0, "", 0, "");
				foreach($arr_resize as $type => $arr){
					resize_image($fs_filepath, $filename, $arr["width"], $arr["height"], $arr["quality"], $type);
				}
                $fs_errorMsg = $upload->show_warning_error();unset($upload);
			}
            //Up ảnh banner
            $upload_banner     = new upload('new_banner', $fs_filepath, $fs_extension, $fs_filesize);
            $filename_banner   = $upload_banner->file_name;
            if($filename_banner != ""){
                $myform->add("new_banner", "filename_banner", 0, 1, "", 0, "", 0, "");
                $fs_errorMsg = $upload_banner->show_warning_error();unset($upload_banner);
            }
            //Chèn slide ảnh
            $slide_type = getValue('slide_type','int','POST',0);
            $slide_record = getValue('slide_record','arr','POST',0);
            if($slide_type){
                if($slide_type == 1){
                    //1 ảnh
                    $new_slide = array();
                    $new_slide['type'] = 1;
                    $upload = new upload('slide_file_1', '../../../pictures/slide_picture/', $fs_extension, $fs_filesize);
                    $filename = $upload->file_name;
                    if($filename){
                        $new_slide['picture'] = $filename;
                        $new_slide = base64_encode(json_encode($new_slide));
                        $myform->add('new_slide','new_slide',0,1,'');    
                    }
                    else{
                        $fs_errorMsg .= $upload->show_warning_error();
                    }
                }
                if($slide_type == 3){
                    //3 ảnh
                    $new_slide = array();
                    $new_slide['type'] = 3;
                    $count = count($slide_record);
                    for($i=0;$i<$count;$i++){
                        $upload = new upload('slide_file_'.$slide_record[$i], '../../../pictures/slide_picture/', $fs_extension, $fs_filesize);
                        $filename = $upload->file_name;
                        if($filename){
                            $new_slide['picture_'.$slide_record[$i]] = $filename;    
                        }
                        else{
                            $fs_errorMsg .= $upload->show_warning_error();
                            break;
                        }
                    }
//                    print_r($new_slide);
                    if($fs_errorMsg == ''){
                        $new_slide = base64_encode(json_encode($new_slide));
                        $myform->add('new_slide','new_slide',0,1,'');    
                    }
                }
            }
			
			if($fs_errorMsg == ""){
				$myform->addTable($fs_table);
				$db_insert 		= new db_execute_return();
				$last_id			= $db_insert->db_execute($myform->generate_insert_SQL());
                //Insert tags
                $string_tags = getValue('new_tags','str','POST','');
                if($string_tags){
                    $arr_tags = explode(',',$string_tags);
                    foreach($arr_tags as $tag){
                        $tag_keyword = md5($tag);
                        $db_ex = new db_execute('INSERT IGNORE tags(tag_keyword,tag_name) 
                                                 VALUES("'.$tag_keyword.'", "'.$tag.'")');
                        unset($db_ex);
                    }
                }
                
                //Cập nhật trạng thái cho bài viết này
                //Các nút chức năng
                $save_temp = getValue('save_temp','int','POST',0);
                $send_direct = getValue('send_direct','int','POST',0);
                $publish = getValue('publish','int','POST',0);
                $schedule = getValue('schedule','int','POST',0);
                
                //Nút lưu lại
                if($admin_role['rol_save_temp'] && $save_temp){
                    $db_fn = new db_execute('UPDATE news 
                                             SET new_status = 0 
                                             WHERE new_id = '.$last_id);
                    unset($db_fn);
                }
                //Nút gửi thẳng
                if($admin_role['rol_send_direct'] && $send_direct){
                    if($admin_role['rol_check']){
                        $db_update_status = new db_execute('UPDATE news SET new_status = 3 WHERE new_id ='.$last_id);
                        unset($db_update_status);
                    }
                    //Nếu đang ở lưu tạm mà ko có quyền duyệt thì tin đc lên chờ biên tập
                    if(!$admin_role['rol_check']){
                        $db_update_status = new db_execute('UPDATE news SET new_status = 1 WHERE new_id ='.$last_id);
                        unset($db_update_status);
                    }
                }
                //Nút xuất bản
                //Nếu có quyền xuất bản thì cập nhật xuất bản    
                if($admin_role['rol_publish']){
                    if($publish){
                        $db_fn = new db_execute('UPDATE news SET new_status = 6 WHERE new_id = '.$last_id);
                        unset($db_fn);    
                    }
                    if($schedule){
                        //Lấy ngày giờ xuất bản
                        $schedule_hour = getValue('schedule_hour','int','POST',0) % 24;
                        $schedule_min = getValue('schedule_min','int','POST',0) % 60;
                        $schedule_sec = getValue('schedule_sec','int','POST',0) % 60;
                        $schedule_date = getValue('schedule_date','str','POST','');
                        $today = getdate();
                        $today = @mktime(0,0,0,$today['mon'],$today['mday'],$today['year']);
                        $schedule_date = $schedule_date ? convertDateTime($schedule_date,'0-0-0') : $today;
                        $new_publish_time = $schedule_date + $schedule_hour*3600 + $schedule_min*60 + $schedule_sec;
                        if($new_publish_time){
                            $db_fn = new db_execute('UPDATE news 
                                                     SET    new_date = '.$new_publish_time.', 
                                                            new_publish_time = '.$new_publish_time. ' 
                                                     WHERE  new_id = '.$last_id);
                        }
                    }
                }
				redirect("listing.php");
			}
		}
	}
	$myform->addFormname("add_new");
	$myform->evaluate();
    //List danh sách các tác giả
    $db_user = new db_query('SELECT aut_id, aut_name FROM authors WHERE aut_active = 1 ORDER BY aut_name ASC');
    $arr_user = array(0=>'Mặc định');
    while($row_user = mysql_fetch_assoc($db_user->result)){
        $arr_user[$row_user['aut_id']] = $row_user['aut_name'];
    }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?=$load_header?>
<? $myform->checkjavascript();?>
<style>
.overlay{
    display:none;
    background:#f0f0f0;
    opacity: 0.5;
    position: fixed;
    width:100%;
    height:100%;
    z-index:10;
}
.popup{
    display:none;
    background:#fff;
    border:2px solid #92D1F5;
    position:absolute;
    z-index:11;
    left:90px;
    width:600px;
    min-height:400px;
}
.popup-header{
    font-size: 15px;
    font-weight: bold;
    text-align: center;
    padding: 0 0 10px 0px;
    border-bottom: 1px solid #CCC;
}
.multifunction{
    padding:20px;
}
.multifunction span{
    padding:3px 8px;
    font-weight: bold;
    font-size:12px;
    text-transform: uppercase;
    border:1px solid #388bb7;
    background:#04347c;
    color:#fff;
    cursor:pointer;
}
</style>
</head>
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<div class="overlay"></div>
<?=template_top(translate_text("Add merchant"))?>
	<p align="center" style="padding-left:10px;">
		<?
		$form = new form();
		$form->create_form("add_new",$fs_action,"post","multipart/form-data","onsubmit='validateForm(); return false;'");
		$form->create_table();
		?>
		<?=$form->text_note('Những ô dấu sao (<font class="form_asterisk">*</font>) là bắt buộc phải nhập.')?>
		<? //Khai bao thong bao loi ?>
		<?=$form->errorMsg($fs_errorMsg)?>
        <?
        //create checkbox chức năng
        $cbID = '';
        $cbID .= $admin_role['rol_save_temp'] ? 'save_temp'.($admin_role['rol_send_direct'] ? $form->ec : '') : '';
        $cbID .= $admin_role['rol_send_direct'] ? 'send_direct' : '';
        
        $cbNm = '';
        $cbNm .= $admin_role['rol_save_temp'] ? 'save_temp'.($admin_role['rol_send_direct'] ? $form->ec : '') : '';
        $cbNm .= $admin_role['rol_send_direct'] ? 'send_direct' : '';
        
        $cbVl = '';
        $cbVl .= $admin_role['rol_save_temp'] ? '1'.($admin_role['rol_send_direct'] ? $form->ec : '') : '';
        $cbVl .= $admin_role['rol_send_direct'] ? '1' : '';
        
        $cbCv = '';
        $cbCv .= $admin_role['rol_save_temp'] ? '0'.($admin_role['rol_send_direct'] ? $form->ec : '') : '';
        $cbCv .= $admin_role['rol_send_direct'] ? '0' : '';
        
        $cbTt = '';
        $cbTt .= $admin_role['rol_save_temp'] ? 'Lưu lại'.($admin_role['rol_send_direct'] ? $form->ec : '') : '';
        $cbTt .= $admin_role['rol_send_direct'] ? 'Gửi thẳng' : '';
        
        $cbHtml = '';
        $cbHtml .= $admin_role['rol_save_temp'] ? ''.($admin_role['rol_send_direct'] ? $form->ec : '') : '';
        $cbHtml .= $admin_role['rol_send_direct'] ? '' : '';
        ?>
        <?=$form->checkbox('Thao tác', $cbID, $cbNm, $cbVl, $cbCv,$cbTt,0,$cbHtml)?>
        <? if($admin_role['rol_publish']):?>
        <tr>
            <td class="form_name"></td>
            <td class="form_text">
                <input type="checkbox" name="publish" id="publish" value="1"/>
                <label for="publish"><?=translate_text('Xuất bản')?></label>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td class="form_name">&nbsp;</td>
            <td class="form_text">
                <input type="checkbox" name="schedule" id="schedule" value="1" />
                <label for="schedule">Hẹn giờ xuất bản</label>
            </td>
        </tr>
        <tr id="schedule_tr" style="display:none;" >
            <td>&nbsp;</td>
            <td>
                <select class="schedule_setting form_control" name="schedule_hour">
                    <option> -Giờ- </option>
                    <?for($i=0;$i<=23;$i++){
                        ?>
                    <option value="<?=$i?>"><?=$i < 10 ? '0'.$i : $i?></option>    
                        <?
                    }?>
                </select>
                <select class="schedule_setting form_control" name="schedule_min">
                    <option> -Phút- </option>
                    <?for($i=0;$i<=59;$i++){
                        ?>
                    <option value="<?=$i?>"><?=$i < 10 ? '0'.$i : $i?></option>    
                        <?
                    }?>
                </select>
                <select class="schedule_setting form_control" name="schedule_sec">
                    <option> -Giây- </option>
                    <?for($i=0;$i<=59;$i++){
                        ?>
                    <option value="<?=$i?>"><?=$i < 10 ? '0'.$i : $i?></option>    
                        <?
                    }?>
                </select>
                <input type="text" class="form_control" name="schedule_date" id="schedule_date" value = "Enter date"  style="width:100px;font-size:11px;" onkeypress="displayDatePicker('schedule_date', this);" onclick="displayDatePicker('schedule_date', this);" onfocus="if(this.value=='Enter date') this.value=''" onblur="if(this.value=='') this.value='Enter date'" />
            </td>
        </tr>
        <?endif;?>
        <? if($admin_role['rol_vip'] == 1 || $admin_role['rol_vip'] == 2):?>
		<?=$form->select_db_multi("Danh mục", "new_cat_id", "new_cat_id", $listAll, "cat_id", "cat_name", $new_cat_id, "Danh mục", 1, "150", 1, 0, "", "")?>
        <? /** danh mục relate **/?>
        <? if($admin_role['rol_edit']):?>
        <tr>
            <td class="form_name">Relate :</td>
            <td class="form_text">
                <?foreach($listAll as $acat): ?>
                <input type="checkbox" value="<?=$acat['cat_id']?>" id="relate_cat_<?=$acat['cat_id']?>" name="relate_cat[]"/>
                <label for="relate_cat_<?=$acat['cat_id']?>">
                    <? if($acat['cat_parent_id']):?>
                    &nbsp;|---&nbsp;
                    <?endif?><?=$acat['cat_name']?>
                </label><br />
                <?endforeach;?>
            </td>
        </tr>
        <?endif;?>
		<? else :?>
        <?=$form->select('Danh mục', 'new_cat_id', 'new_cat_id',$listAll,0,'Danh mục',1)?>
        <? /** danh mục relate **/?>
        <? if($admin_role['rol_edit']):?>
        <tr>
            <td class="form_name">Relate :</td>
            <td class="form_text">
                <?foreach($listAll as $k=>$v): ?>
                <? if($k == 0) continue;?>
                <input type="checkbox" value="<?=$k?>" id="relate_cat_<?=$k?>" name="relate_cat[]"/>
                <label for="relate_cat_<?=$k?>">
                    <?=$v?>
                </label><br />
                <?endforeach;?>
            </td>
        </tr>
        <?endif;?>
        <? endif?>
        <tr>
            <td class="form_name">Sự kiện :</td>
            <td class="form_text">
                <select class="form_control" id="new_event_id" name="new_event_id" disabled="disabled">
                    <option>-- Chọn event --</option>
                </select>
            </td>
        </tr>
        <? /*   Pitching    */?>
        <tr>
            <td class="form_name">Pitching :</td>
            <td class="form_text">
                <select class="form_control" id="new_pitching_id" name="new_pitching_id" disabled="disabled">
                    <option>-- Chọn pitching --</option>
                </select>
            </td>
        </tr>
		<?=$form->text("Tiêu đề", "new_title", "new_title", $new_title, "Tiêu đề tin", 1, 350)?>
        <?/*    chọn tin liên quan  */?>
        <tr>
            <td class="form_name" valign="top">Tin liên quan :</td>
            <td class="form_text">
                <input type="text" style="width:350px" placeholder="Search theo tiêu đề, tag" class="form_control" id="search_news_relate"/>
                <div class="search_news_result">
                    <ul>
                    
                    </ul>
                </div>
                <div class="news_relate_after_search">
                
                </div>
            </td>
        </tr>
        <tr>
            <td class="form_name" valign="top">Tin gợi ý :</td>
            <td class="form_text">
                <input type="text" style="width:350px" placeholder="Search theo tiêu đề, tag" class="form_control" id="search_news_recommend"/>
                <div class="search_news_recommend_result">
                    <ul>
                    
                    </ul>
                </div>
                <div class="news_recommend_after_search">
                
                </div>
            </td>
        </tr>
		<?=$form->getFile("Ảnh đại diện", $fs_fieldupload, $fs_fieldupload, "Ảnh đại diện của tin", 0, 30, "", "")?>
        <?=$form->getFile("Ảnh banner", 'new_banner', 'new_banner', "Ảnh banner của tin", 0, 30, "", "")?>
		<tr>
            <td class="form_name">Ảnh slide :</td>
            <td class="form_text">
                <div id="NewsSlide">
                    
                </div>
            </td>
        </tr>
        <?=$form->text("Tag bài viết","new_tags","new_tags", $new_tags,"Một số từ khóa liên quan đến bài viết, các nhau bởi dấu phải và mỗi từ không được dài quá 3 chữ.", 0, "350","","","",""," Cách nhau bởi dấu phẩy.")?>
        <?=$form->text('Tag sang Base','new_tags_to_base','new_tags_to_base',$new_tags_to_base,'Tag tin tới Vcamp Base',0,350,'','','','',' Tag tin tới Vcamp Base')?>
		<? if($admin_role['rol_vip'] == 1 || $admin_role['rol_vip'] == 2){?>
        <tr>
            <td class="form_name">Nổi bật :</td>
            <td class="form_text">
                <div><input type="checkbox" name="new_top_index" value="1"/>&nbsp;Nổi bật trang chủ</div>
                <div><input type="checkbox" name="new_top" value="1"/>&nbsp;Nổi bật mục</div>
            </td>
        </tr>
        <?}?>
        <? if($admin_role['rol_vip'] || $admin_role['rol_edit']){?>
        <?=$form->checkbox('Tiêu điểm','new_focus','new_focus',1,$new_focus,'Tin xuất hiện ở mục tiêu điểm')?>
        <?=$form->checkbox('Tin hot','new_hot','new_hot',1,$new_hot,'Tin xuất hiện ở mục tin hot')?>
        <?}?>
        <?=$form->select('Nguồn','new_sou_id','new_sou_id',$arr_source,0)?>
        <?=$form->select('Chọn tác giả','new_author','new_author',$arr_user,0)?>
        <?=$form->textarea("Tóm tắt", "new_teaser", "new_teaser", $new_teaser, "Tóm tắt của tin", 1, 600,100)?>
        <?=$form->text("Giá tiền","new_coin","new_coin",$new_coin,"Giá tiền của tin")?>
        <?=$form->close_table();?>
        <div class="multifunction">
            <span id="add_image">Thêm ảnh</span>
            <span id="add_gallery">Thêm gallery</span>
        </div>
        <div class="popup" draggable="draggable"></div>
		<?=$form->tinyMCE('Bài viết','new_detail','new_detail',getValue('new_detail','str','POST',''),'90%')?>
        <?=$form->create_table();?>
		<?=$form->button("submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "Thêm mới" . $form->ec . "Làm lại", "Cập nhật" . $form->ec . "Làm lại", 'style="background:url(' . $fs_imagepath . 'button_1.gif) no-repeat"' . $form->ec . 'style="background:url(' . $fs_imagepath . 'button_2.gif)"', "");?>
		<?=$form->hidden("action", "action", "execute", "");?>
		<?
		$form->close_table();
		$form->close_form();
		unset($form);
		?>
	 </p>
<?=template_bottom() ?>
<script>
	$(function(){
		$('#ned_teaser').wysiwyg({controls: {cut   : { visible : true },copy  : { visible : true },paste : { visible : true }}});
	});
    $('#new_cat_id').change(function(){
        catID = $(this).val();
        $.ajax({
            type:'post',
            url:'ajax.php',
            data:{action:'add_change_cat',catID:catID},
            dataType:'html',
            success:function(html){
                $('#new_event_id').html(html).removeAttr('disabled');
            }
        });
        $.ajax({
            type:'post',
            url:'ajax.php',
            data:{action:'add_slide',catID:catID},
            dataType:'html',
            success:function(html){
                $('#NewsSlide').html(html);
            }
        });
        $.ajax({
            type:'post',
            url:'ajax.php',
            data:{action:'add_pitching',catID:catID},
            dataType:'html',
            success:function(html){
                $('#new_pitching_id').html(html).removeAttr('disabled');
            }
        });
    });
    //Hẹn giờ
    $('#schedule').click(function(){
        if(!$(this).attr('checked')){
            //Ẩn box hẹn giờ
            $('#schedule_tr').hide();
        }else{
            $('#schedule_tr').show();
        }
    });
    //Các nút chức năng
    $('#add_image').click(function(){
        $('.overlay').show();
        $('.popup').show();
        //Load ajax
        $.ajax({
            type:'post',
            url:'ajax.php',
            data:{action:'add_image'},
            success:function(resp){
                $('.popup').html(resp);
            }
        });
        $('.overlay').click(function(){
            $('.popup').hide();
            $('.overlay').hide();
        })
    });
    $('#add_gallery').click(function(){
        $('.overlay').show();
        $('.popup').show();
        $.ajax({
            type:'post',
            url:'ajax.php',
            data:{action:'add_gallery'},
            success:function(html){
                $('.popup').html(html);
            }
        })
        $('.overlay').click(function(){
            $('.popup').hide();
            $('.overlay').hide();
        })
    });
    //Search tin liên quan để add vào
    $('#search_news_relate').keyup(function(){
        $.ajax({
            type:'post',
            url:'ajax.php',
            data:{action:'search_news_relate',kw:$(this).val()},
            success:function(resp){
                $('.search_news_result ul').html(resp);
            }
        })
    });
    $('#search_news_recommend').keyup(function(){
        $.ajax({
            type:'post',
            url:'ajax.php',
            data:{action:'search_news_recommend',kw:$(this).val()},
            success:function(resp){
                $('.search_news_recommend_result ul').html(resp);
            }
        })
    });
    //Hàm add tin vào danh sách tin liên quan
    function addNewsRelate(){
        var array_relate_list = [];
        $('.new_relate_result').each(function(){
            if($(this).attr('checked') == 'checked'){
                dataRN = {
                    value:$(this).val(),
                    title:$(this).attr('title')
                }
                array_relate_list.push(dataRN);    
            }
        });
        if(array_relate_list){
            var listBuild = '<ul>';
            for(i in array_relate_list){
                var buildEle = '';
                buildEle += '<input type="checkbox" name="new_relate_list[]" value="'+array_relate_list[i].value+'" id="new_relate_list_'+array_relate_list[i].value+'"/>';
                buildEle += '<label for="new_relate_list_'+array_relate_list[i].value+'">'+array_relate_list[i].title+'</label>';
                buildEle += '<span style="padding:5px;color:red;font-weight:bold;font-size:14px;cursor:pointer;" onclick="del_new_relate(this)">&times;</button>';
                listBuild += '<li>';
                listBuild += buildEle;
                listBuild += '</li>';    
            }
            listBuild += '</ul>';
            $('.news_relate_after_search').append(listBuild);
        }
    }
    function addNewsRecommend(){
        var array_relate_list = [];
        $('.new_recommend_result').each(function(){
            if($(this).attr('checked') == 'checked'){
                dataRN = {
                    value:$(this).val(),
                    title:$(this).attr('title')
                }
                array_relate_list.push(dataRN);    
            }
        });
        if(array_relate_list){
            var listBuild = '<ul>';
            for(i in array_relate_list){
                var buildEle = '';
                buildEle += '<input type="checkbox" name="new_recommend_list[]" value="'+array_relate_list[i].value+'" id="new_recommend_list_'+array_relate_list[i].value+'"/>';
                buildEle += '<label for="new_recommend_list_'+array_relate_list[i].value+'">'+array_relate_list[i].title+'</label>';
                buildEle += '<span style="padding:5px;color:red;font-weight:bold;font-size:14px;cursor:pointer;" onclick="del_new_relate(this)">&times;</button>';
                listBuild += '<li>';
                listBuild += buildEle;
                listBuild += '</li>';    
            }
            listBuild += '</ul>';
            $('.news_recommend_after_search').append(listBuild);
        }
    }
    function del_new_relate(a){
        $(a).closest('li').remove();
    }
</script>
</body>
</html>